<%@ page language="java" contentType="text/html; charset=gbk" pageEncoding="gbk"%>
<%@ page import="java.util.*" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.activiti.engine.ProcessEngine" %>
<%@ page import="org.activiti.engine.RepositoryService" %>
<%@ page import="org.activiti.engine.RuntimeService" %>
<%@ page import="org.activiti.engine.FormService" %>
<%@ page import="org.activiti.engine.repository.ProcessDefinition" %> 
<%@ page import="org.activiti.engine.form.StartFormData" %>
<%@ page import="org.activiti.engine.form.FormProperty" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link type="text/css" rel="stylesheet" charset="utf-8" href="<%=request.getContextPath() %>/css/base.css"/>
<title>Process Definition</title>
</head>
<%
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
//ProcessEngine engine = (ProcessEngine)context.getBean("processEngine");
RepositoryService repository = (RepositoryService)context.getBean("repositoryService");
RuntimeService runtime = (RuntimeService)context.getBean("runtimeService");
FormService form = (FormService)context.getBean("formService");

List<FormProperty> formProperties = null;
String doWhat = request.getParameter("doWhat");
if(doWhat != null && doWhat.equals("start")){
	StartFormData formData = form.getStartFormData(request.getParameter("processDefinitionId"));
	formProperties = formData.getFormProperties();
	//runtime.startProcessInstanceById(request.getParameter("processDefinitionId"));
}
//List<ProcessDefinition> list = repository.createProcessDefinitionQuery().list();
List<ProcessDefinition> list = repository.createProcessDefinitionQuery().latestVersion().list();
%>
<body>
<table align="center" width="100%">
	<caption>ProcessDefinitions</caption> 
	<tr>
		<th align="center" scope="col">Id</th>
		<th align="center" scope="col">key</th>
		<th align="center" scope="col">name</th>
		<th align="center" scope="col">version</th>
		<th align="center" scope="col">DeploymentId</th>
		<th align="center" scope="col">Category</th>
		<th align="center" scope="col">DiagramResourceName</th>
		<th align="center" scope="col">ResourceName</th>
		<th align="center" scope="col">hasStartFormKey</th>
		<th align="center" scope="col">isSuspended</th>
		<th align="center" scope="col"></th>
	</tr>
	<%for(ProcessDefinition d : list){%>
	<tr>
		<td class="row"><%=d.getId() %></td>
		<td class="row"><%=d.getKey() %></td>
		<td class="row"><%=d.getName() %></td>
		<td class="row"><%=d.getVersion() %></td>
		<td class="row"><%=d.getDeploymentId() %></td>
		<td class="row"><%=d.getCategory() %></td>
		<td class="row"><%=d.getDiagramResourceName() %></td>
		<td class="row"><%=d.getResourceName() %></td>
		<td class="row"><%=d.hasStartFormKey() %></td>
		<td class="row"><%=d.isSuspended() %></td>
		<td class="row"><a href="<%=request.getContextPath() %>/jsp/startProcess.jsp?doWhat=start&processDefinitionId=<%=d.getId() %>">start</a></td>
	</tr>
	<%} %>
</table>
</body>
</html>